package com.example.home_model;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.LogUtils;
import com.bw.ijk.widget.IjkView;
import com.example.baseadapter_sdk.BaseQuickMultipleAdapter;
import com.example.baseadapter_sdk.BaseViewHolder;
import com.example.home_model.entity.DataDTO;

public class HomeMultipleAdapter extends BaseQuickMultipleAdapter<DataDTO>  {

    public HomeMultipleAdapter() {
        addItemChildClick(R.id.button_diss,R.id.button_liek,R.id.button_comment,R.id.button_share);
    }

    @Override
    public void convert(BaseViewHolder holder, DataDTO item) {
        if (item.itemType == 0){
            holder.setText(R.id.username_top, item.author.name);
            holder.setText(R.id.user_title, item.feeds_text);
            holder.setText(R.id.button_liek, ""+item.ugc.likeCount);
            holder.setText(R.id.button_diss, "踩");
            if (item.topComment!=null){
                holder.setText(R.id.button_comment, ""+item.ugc.commentCount);
                holder.setText(R.id.button_share, ""+item.ugc.shareCount);
                holder.setText(R.id.feed_tag, item.activityText);
                holder.setText(R.id.comment_username, item.topComment.author.name);
                holder.setText(R.id.comment_btn_like, ""+item.topComment.ugc.likeCount);
                holder.setText(R.id.comment_text, item.topComment.commentText);
            }

        }else if (item.itemType == 1){
            //图片资源
            holder.setText(R.id.username_top, item.author.name);
            holder.setText(R.id.user_title, item.feeds_text);
            holder.setImage(R.id.feed_image,item.cover);
            holder.setText(R.id.button_liek, ""+item.ugc.likeCount);
            holder.setText(R.id.button_diss, "踩");
            if (item.topComment!=null){
                holder.setText(R.id.button_comment, ""+item.ugc.commentCount);
                holder.setText(R.id.button_share, ""+item.ugc.shareCount);
                holder.setText(R.id.feed_tag, item.activityText);
                holder.setText(R.id.comment_username, item.topComment.author.name);
                holder.setText(R.id.comment_btn_like, ""+item.topComment.ugc.likeCount);
                holder.setText(R.id.comment_text, item.topComment.commentText);
            }
        }else if (item.itemType == 2){
            //视频资源
            holder.setText(R.id.username_top, item.author.name);
            holder.setText(R.id.user_title, item.feeds_text);
            IjkView ijkView = holder.getView(R.id.feed_video);
            ijkView.setPlayUrl(item.url,item.cover);
            holder.setText(R.id.button_liek, ""+item.ugc.likeCount);
            holder.setText(R.id.button_diss, "踩");
            if (item.topComment!=null){
                holder.setText(R.id.button_comment, ""+item.ugc.commentCount);
                holder.setText(R.id.button_share, ""+item.ugc.shareCount);
                holder.setText(R.id.feed_tag, item.activityText);
                holder.setText(R.id.comment_username, item.topComment.author.name);
                holder.setText(R.id.comment_btn_like, ""+item.topComment.ugc.likeCount);
                holder.setText(R.id.comment_text, item.topComment.commentText);
            }

        }
    }

    @Override
    protected View createItemVIew(int viewType, ViewGroup parent) {
        if (viewType == 0){
            //文字资源
            View inflate = LayoutInflater.from(getContext()).inflate(R.layout.item_feed_type_text, parent, false);
            return inflate;
        }else if (viewType == 1){
            //图片资源
            View inflate = LayoutInflater.from(getContext()).inflate(R.layout.item_feed_type_image, parent, false);
            return inflate;
        }else if (viewType == 2){
            //视频资源
            View inflate = LayoutInflater.from(getContext()).inflate(R.layout.item_feed_type_video, parent, false);
            return inflate;

        }
        return null;
    }

    @Override
    public int getItemType(int position) {
        return getData().get(position).itemType;
    }
}
